package com.mobile.collect.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.mobile.collect.R;

import java.util.ArrayList;
import java.util.List;

import cn.droidlover.xdroidmvp.base.BaseRecyclerAdapter;
import cn.droidlover.xdroidmvp.base.ListViewItemClickListener;
import cn.droidlover.xdroidmvp.base.RecyclerViewHolder;

/**
 * 类名: KeyBroadPop
 * 作者: 李学伟
 * 日期: 2020年09月22日 16:39
 * 描述: dialog_keybroad
 */
public class NumberPop extends InputDialog {

    RecyclerView numberView;
    BaseRecyclerAdapter<String> numberAdapter;

    public NumberPop(@NonNull Context context,  String label, String oldTxt, InputCompleteListener listener,int maxCount) {
        super(context, label,oldTxt, listener, R.layout.dialog_number, maxCount);
    }

    @Override
    protected void initViews() {
        super.initViews();
        numberView = findViewById(R.id.numberView);
        numberView.setLayoutManager(new GridLayoutManager(context, 3));
        numberAdapter = new BaseRecyclerAdapter<String>(context) {
            @Override
            public int getItemLayoutId(int viewType) {
                return R.layout.item_latters;
            }

            @Override
            public void bindData(RecyclerViewHolder holder, int position) {
                super.bindData(holder, position);
                holder.setText(R.id.valueTv, getItemByPosition(position));
            }
        };
        numberView.setAdapter(numberAdapter);
        numberAdapter.addList(true, getNumbers());

        numberAdapter.setItemClickListener(new ListViewItemClickListener() {
            @Override
            public void itemClick(int position) {
                if (position == numberAdapter.getItemCount()-1) {
                    del();
                }else{
                    appendText(numberAdapter.getItemByPosition(position));
                }
            }
        });
    }


    private List<String> getNumbers() {
        List<String> datas = new ArrayList<>();
        for (int i = 1; i <= 9; i++) {
            datas.add(String.valueOf(i));
        }
        datas.add("0");
        datas.add(".");
        datas.add("删除");
        return datas;
    }


}
